﻿using HomagChina.CCHS.Views;
using HomagGroup.Base.UI;
using HomagGroup.Base.UI.Controls;
using HomagGroup.Base.UI.Windows;
using Proxy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using HomagChina.Basic.CCT.Tools;
using LocalText = Proxy.Properties.Resources;

namespace HomagChina.CCHS.ViewModels
{
    public class BoardImportViewModel : NotifyPropertyChangedBase
    {
        ModifyInfoHandle Handle_ModifyInfo;
        CommonHandle Handle_Common;
        public RelayCommand NextCommand { get; }

        private string _Title;
        public string Title
        {
            get => _Title;
            set { _Title = value; OnPropertyChanged(); }
        }
        public DropDownList DropDownList_Format { get; set; }
        /// <summary>
        /// Dropdown list
        /// </summary>
        public object SelectedValue = "csv";

        public BoardImportViewModel()
        {
            Title = LocalText.Import;
            NextCommand = new RelayCommand(Next);
            Init();
        }


        public void Init()
        {
            DropDownList_Format = new DropDownList
            {
                ItemsSource = (new List<string>() { { "csv" }, { "bdx" } }),
                SelectedIndex = 0
            };
            DropDownList_Format.SelectionChanged += DropDownList_SelectionChanged;
        }

        private void DropDownList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SelectedValue = ((DropDownList)sender).SelectedItem.ToString();
        }

        public void Next()
        {
            HandleOpenMprFile();
        }

        /// <summary>
        /// 
        /// </summary>
        public void HandleOpenMprFile()
        {
            try
            {
                string format = SelectedValue.ToString();
                switch (format)
                {
                    case "csv":
                        format = "csv files (*.csv, *.csv)|*.csv;*.csv";
                        break;
                    case "bdx":
                        format = "bdx files (*.bdx, *.bdx)|*.bdx;*.bdx";
                        break;
                    default:
                        break;
                }

                format += "|All files (*.*)|*.*";
                var data = new FileDialogData()
                {
                    //固定路径
                    InitialDirectory = @"C:\Users\tb28who\Desktop\Homag\Homag Project Info\Horizontal Storage\Description\Boardlibrary data",
                    //文件格式
                    Filter = format,
                    //特点
                    Features = FileDialogData.FeaturesModes.CanShowPreview,
                };
                if (UIAdjustments.CurrentThreadDialogManager.FileDialog.SelectFiles(Application.Current.MainWindow, data) == true)
                {
                    BoardPreviewViewModel boardPreviewViewModel = new BoardPreviewViewModel(data.FileName, SelectedValue.ToString());
                    UIAdjustments.CurrentThreadDialogManager.ShowDialog<BoardPreview>(boardPreviewViewModel, null);
                }
            }
            catch (Exception ex)
            {
                //SerilogHandle.Logger_DealWithCsv.Error(ex.Message);
            }
        }
    }
}
